﻿using NodeEditor;
using UnityEngine;

namespace ETHotfix
{
    [NodeEvent(typeof(PlayAnimationNode))]
    public class PlayAnimationNodeHandle : NodeHandle<PlayAnimationNode>
    {
        protected override void OnHandle(RuntimeTree runtimeTree, RuntimeNode runtimeNode, PlayAnimationNode data, Unit unit)
        {
            var rc = unit.target.GetComponent<ReferenceCollector>();
            if (rc == null)
                return;

            var go = rc.Get<GameObject>(data.gameObjectName);
            if (go == null)
                return;

            var animator = go.GetComponent<Animator>();
            if (animator == null)
                return;

            animator.Play(data.animationName);
        }
    }
}